package com.laozj.test.listener;

import com.laozj.test.config.RabbitMQConfig;
import com.laozj.test.service.UserService;
import com.laozj.test.vo.UserVO;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class UserSyncListener {

    @Autowired
    private UserService userService;

    /**
     * 监听指定队列，接收消息
     * @param message 消息内容
     */
    @RabbitListener(queues = RabbitMQConfig.USER_QUEUE)
    public void receiveMessage(UserVO message) {
        System.out.println("UserSyncListener receiveMessage：" + message);
        // 处理消息的业务逻辑
        userService.saveEntity(message);
    }

}
